package com.zpark.signup.controller;

import com.zpark.signup.dto.UserDto;
import com.zpark.signup.dto.UserPwdDto;
import com.zpark.signup.entity.Admin;
import com.zpark.signup.entity.ApplyForm;
import com.zpark.signup.entity.User;
import com.zpark.signup.service.UserService;
import com.zpark.signup.utils.R;
import com.zpark.signup.utils.RespPageBean;
import com.zpark.signup.validate.ValidatedGroup;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;


    @ApiOperation("删除用户")
    @DeleteMapping
    public R deleteUser(Integer id) {
        return userService.deleteUser(id);
    }


    @ApiOperation("查询所有用户信息（多条件+分页）")
    @GetMapping
    public RespPageBean selectUserByExampleAndPage(UserDto userDto) {
        return userService.selectUser(userDto);
    }

    /**
     * 规定控制层方法返回值类型全部为R或者是RespPageBean
     */
//    @RequestBody 注解不能用于get请求
    @ApiOperation("用户注册")
    @PostMapping("/register")
    public R register(@RequestBody @Validated(value = ValidatedGroup.CREATE.class) User user) {
//        System.out.println("--------------------");
        return userService.registerUser(user);
    }


    @ApiOperation("修改用户基本信息")
    @PostMapping
    public R updateUser(@RequestBody @Validated(value = ValidatedGroup.UPDATE.class) User user) {
        return userService.updateUser(user);
    }


    @ApiOperation("修改用户密码")
    @PostMapping("/pwd")
    public R updatePassword(@RequestBody UserPwdDto userPwdDto) {
        return userService.updateUserPassword(userPwdDto);
    }

    @ApiOperation("查询用户信息")
    @GetMapping("/{id}")
    public R getUser(@PathVariable Integer id) {
        return userService.selectUser(id);
    }
}
